﻿Public Class LinhKienMayTinhMasterPage
    Inherits System.Web.UI.MasterPage

#Region "Khai báo các biến toàn cục"

    ''' <summary>
    ''' danh sach link javascript
    ''' </summary>
    ''' <remarks></remarks>
    Protected ScriptLinkList As New List(Of String)

    ''' <summary>
    ''' danh sach link css
    ''' </summary>
    ''' <remarks></remarks>
    Protected CssLinkList As New List(Of String)

#End Region

#Region "Khai báo các event"

    ''' <summary>
    ''' Page_Load
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    ''' <remarks></remarks>
    ''' <history version="1" date="2013.02.08" name="TRUNG-DD">Tạo mới</history>
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Try
            Dim meta As HtmlMeta = Page.Header.FindControl("Keywords")
            If meta Is Nothing Then
                Dim keyword As New HtmlMeta
                keyword.Name = "keywords"
                keyword.ID = "Keywords"
                keyword.Content = ConfigurationManager.AppSettings("keywords")
                Page.Header.Controls.Add(keyword)
            End If

            meta = Page.Header.FindControl("Description")
            If meta Is Nothing Then
                Dim description As New HtmlMeta
                description.Name = "description"
                description.ID = "Description"
                description.Content = ConfigurationManager.AppSettings("SiteDescription")
                Page.Header.Controls.Add(description)
            End If
        Catch ex As Exception
            Server.Transfer("~/Pages/Error.aspx")
        End Try
    End Sub

    ''' <summary>
    ''' Page_PreRender
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    ''' <remarks></remarks>
    Private Sub Page_PreRender(sender As Object, e As System.EventArgs) Handles Me.PreRender
        Try
            For Each xLink As String In CssLinkList
                AddCssToPage(xLink)
            Next

            For Each xLink As String In ScriptLinkList
                AddScriptToPage(xLink)
            Next
        Catch ex As Exception
            Server.Transfer("~/Pages/Error.aspx")
        End Try

    End Sub

    Private Sub Page_Init(sender As Object, e As System.EventArgs) Handles Me.Init
        Try
            'CssLinkAdd(ResolveUrl("~/Style/CommonStyle.css"))
            CssLinkAdd(ResolveUrl("~/Style/CommonMetroStyle.css"))
            CssLinkAdd(ResolveUrl("~/Style/jquery-ui-1.10.0.custom.css"))
            CssLinkAdd(ResolveUrl("~/Style/FontAwesome/css/font-awesome.min.css"))
            ''bootstrap style
            CssLinkAdd(ResolveUrl("~/Style/css/bootstrap.min.css"))
            CssLinkAdd(ResolveUrl("~/Style/css/bootstrap-responsive.min.css"))

            ScriptLinkAdd(ResolveUrl("~/Scripts/jquery-1.8.3.js"))
            ScriptLinkAdd(ResolveUrl("~/Scripts/jquery.cookie.js"))
            ScriptLinkAdd(ResolveUrl("~/Scripts/jquery-ui-1.10.0.custom.js"))
            ScriptLinkAdd(ResolveUrl("~/Scripts/PageSetting.js"))

            ''bootstrap script
            ScriptLinkAdd(ResolveUrl("~/Scripts/js/bootstrap.min.js"))
        Catch ex As Exception
            Server.Transfer("~/Pages/Error.aspx")
        End Try

    End Sub

#End Region

#Region "Khai báo các function medthod"

    ''' <summary>
    ''' Add css link den trang
    ''' </summary>
    ''' <param name="linkPath"></param>
    ''' <remarks></remarks>
    Protected Sub AddCssToPage(linkPath As String)

        Dim cssLink As New HtmlLink        
        cssLink.Href = linkPath
        cssLink.Attributes("rel") = "stylesheet"
        cssLink.Attributes("type") = "text/css"
        cssLink.Attributes("charset") = "UTF-8"
        Me.Page.Header.Controls.Add(cssLink)

    End Sub

    ''' <summary>
    ''' add css link den danh sach link css
    ''' </summary>
    ''' <param name="linkPath"></param>
    ''' <remarks></remarks>
    Protected Friend Sub CssLinkAdd(linkPath As String)

        If Not CssLinkList.Contains(linkPath) Then
            CssLinkList.Add(linkPath)
        End If

    End Sub

    ''' <summary>
    ''' add script den page
    ''' </summary>
    ''' <param name="linkPath"></param>
    ''' <remarks></remarks>
    Protected Sub AddScriptToPage(linkPath As String)

        Dim scriptLink As New ScriptReference(linkPath)
        scriptLink.ScriptMode = ScriptMode.Release
        Me.ScriptMan.Scripts.Add(scriptLink)        

    End Sub

    ''' <summary>
    ''' add script link den danh sach
    ''' </summary>
    ''' <param name="linkPath"></param>
    ''' <remarks></remarks>
    Protected Friend Sub ScriptLinkAdd(linkPath As String)

        If Not ScriptLinkList.Contains(linkPath) Then
            ScriptLinkList.Add(linkPath)
        End If

    End Sub

#End Region

End Class